package TestDemo;

import java.util.Random;

public class CatandDog {

	public static void main(String[] args) {
		role Cat=new role();
		role Dog=new role();
        Random ran = new Random();
        Cat.health = ran.nextInt(50)+50;
        Cat.aggressivity = ran.nextInt(20)+30;
        Cat.defense = ran.nextInt(10)+20;
        Cat.speed = ran.nextInt(100);
        Dog.health = ran.nextInt(50)+50;
        Dog.aggressivity = ran.nextInt(20)+30;
        Dog.defense = ran.nextInt(10)+20;
        Dog.speed = ran.nextInt(100);
        //游戏开始时展示猫与狗的状态
        System.out.println("猫的状态");
        Cat.state();
        System.out.println("狗的状态");
        Dog.state();
        //猫狗开始对决
        //设置循环，最大回合数不能超过5回合
        //猫先手
        if(Cat.speed>Dog.speed){


          for(int i=1; i<6 ;i++) {
              Dog.health = Dog.health - Cat.aggressivity + Dog.defense;
              if (Dog.health <= 0) {
                System.out.println("游戏结束，猫胜利");
                System.out.println("猫的生命值：" + Cat.health);
                System.out.println("狗的生命值：" + Dog.health);

                break;
              }
              else {
                Cat.health = Cat.health - Dog.aggressivity + Cat.defense;
                if (Cat.health <= 0) {
                    System.out.println("游戏结束，狗胜利");
                    System.out.println("猫的生命值：" + Cat.health);
                    System.out.println("狗的生命值：" + Dog.health);
                    break;
                } else {
                    System.out.println("第" + i + "回合结束");
                    System.out.println("猫的生命值：" + Cat.health);
                    System.out.println("狗的生命值：" + Dog.health);
                }
              }
              //如果超过了最大回合数
              if(i==5){
                  if(Cat.health>Dog.health){
                      System.out.println("游戏结束，猫胜利");
                  }
                  else{
                      System.out.println("游戏结束，狗胜利");
                  }
              }
          }
        }
        //狗先手
        else{
            for(int i=1; i<6 ;i++) {

                Cat.health = Cat.health - Dog.aggressivity + Cat.defense;
                if (Cat.health <= 0) {
                    System.out.println("游戏结束，狗胜利");
                    System.out.println("猫的生命值：" + Cat.health);
                    System.out.println("狗的生命值：" + Dog.health);
                    break;
                }
                else {
                    Dog.health = Dog.health - Cat.aggressivity + Dog.defense;
                    if (Dog.health <= 0) {
                        System.out.println("游戏结束，猫胜利");
                        System.out.println("猫的生命值：" + Cat.health);
                        System.out.println("狗的生命值：" + Dog.health);
                        break;
                    } else {
                        System.out.println("第" + i + "回合结束");
                        System.out.println("猫的生命值：" + Cat.health);
                        System.out.println("狗的生命值：" + Dog.health);

                    }
                }
                //如果超过了最大回合数
                if(i==5){
                    if(Cat.health>Dog.health){
                        System.out.println("游戏结束，猫胜利");
                    }
                    else{
                        System.out.println("游戏结束，狗胜利");
                    }
                }
            }

        }


    }

}
class role{
	int health;
	int aggressivity;
	int defense;
	int speed;
	public void state() {
		System.out.println("生命值:"+health);
		System.out.println("攻击力:"+aggressivity);
		System.out.println("防御力:"+defense);
		System.out.println("速度:"+speed);
	}
	public int getHealth() {
		return health;
	}
	public void setHealth(int health) {
		this.health = health;
	}
	public int getAggressivity() {
		return aggressivity;
	}
	public void setAggressivity(int aggressivity) {
		this.aggressivity = aggressivity;
	}
	public int getDefense() {
		return defense;
	}
	public void setDefense(int defense) {
		this.defense = defense;
	}
	public int getSpeed() {
		return speed;
	}
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	
}
